//在html中添加测试脚本节点
//  <script defer="defer" type="text/javascript" src="../test/test.js"></script>

//在body标记中添加属性
//  onload="testMainframe()"

//主方法标记 // mark html文件全名 方法名 如：//@ popLogin.html testPopLogin
//perl脚本或其他语言来读取这些标记并对响应的问题做修改


//公用的方法

function testCrossDomain(url, jsonStringData){
    //跨域请求的方法
    //isonStringData需要传入json字符串 192.168.52.109
    var domain = "http://192.168.52.109:8080/";
    var completePath = domain + url;
    var scriptSrc = document.createElement("script");
    scriptSrc.src = completePath + "?" + jsonStringData;
    scriptSrc.charset = 'UTF-8';
    document.getElementsByTagName('head')[0].appendChild(scriptSrc);
}

function testSendResult(CheckPointJsonStr, caseId, testFileName, description){
    //alert(CheckPointJsonStr);
    var testResultJsonStr;

    //验证点json数组字符串
    var checkPointObject = "\"testPoints\":" + CheckPointJsonStr + "";
    //用例id
    var caseIdObject = "\"caseId\":\"" + caseId + "\"";
    //测试文件名
    var testFileNameObject = "\"testFileName\":\"" + testFileName + "\"";
    //测试描述
    var descriptionObject = "\"description\":\"" + description + "\"";
    //组装json
    testResultJsonStr = "jsonString={";
    testResultJsonStr = testResultJsonStr + caseIdObject + "," + checkPointObject + "," + testFileNameObject + "," + descriptionObject;
    testResultJsonStr = testResultJsonStr + "}";
    //测试完成发送测试结果
    testCrossDomain("SaveTestResult", testResultJsonStr);
}

function testMyInput(inputObject, valueString){
    //输入，并获取焦点
    inputObject.focus();
    inputObject.value = valueString;
}

function testMyClick(buttonObject){
    //点击并获取焦点
    buttonObject.focus();
    buttonObject.click();
}

function testShowNodes(nodeObject){
    //获取对象后列出对象的所有子孙节点和属性
    //在没有程序员帮助和无法使用调试界面的情况下非常有用
    var newlineMark = "<br>";
    var level = 0;
    var resultString = "";

    function testShowThisNodeInner(nodeObject, level, resultString){
        var mynodeName = nodeObject.nodeName;
        var levelInner = level;

        //节点前的标记符号，用来区分层级
        for (var l=0; l<levelInner; l++){
            resultString = resultString + "-";
        }

        //输出节点类型，（gogoal2.0暂时无法获取节点名 ，不明原因）
        resultString = resultString + "[" + mynodeName + "]";

        //输出节点属性
        for	(var i=0; i<nodeObject.attributes.length; i++){
            var k = nodeObject.attributes.item(i).nodeName;
            var v = nodeObject.getAttribute(k);
            resultString = resultString + " " + k + "=\"" + v +"\" ";
        }

        //输出换行符
        resultString = resultString + newlineMark;

        //判断是否有子节点，并且判断不是TABLE标签
        if(nodeObject.hasChildNodes()){
            var myChildren = nodeObject.children;
            level = level + 1;
            for(var x=0; x<myChildren.length; x++){
                resultString = testShowThisNodeInner(myChildren[x], level, resultString);
            }
        }
        return resultString;
    }

    resultString = testShowThisNodeInner(nodeObject, level, resultString);
    document.write(resultString);
    //alert(resultString);
}

